﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SpiderContract;
using System.ServiceModel;

namespace TKWeb.Tool
{
	public partial class ReCrawl : System.Web.UI.Page
	{
		protected void Page_Load(object sender, EventArgs e)
		{
			if (!this.IsPostBack)
			{
				ddlJob.DataSource = Global.DBAccess.GetTable("select * from crawl_job");
				ddlJob.DataTextField = "name";
				ddlJob.DataValueField = "job_id";
				ddlJob.DataBind();
			}
		}

		protected void btnOK_Click(object sender, EventArgs e)
		{
			using (ChannelFactory<ISpiderService> channelFactory = new ChannelFactory<ISpiderService>("TK.SpiderService"))
			{
				ISpiderService spider = channelFactory.CreateChannel();
				spider.ReCrawl(Convert.ToInt32(ddlJob.SelectedValue), tbUrl.Text.Split(new string[]{ "\r\n" },  StringSplitOptions.None));
			}
		}
	}
}